//
// Created by Administrator on 2019/6/6 0006.
//

#ifndef FFMPEGDEMO_FFMPEGCONTROL_H
#define FFMPEGDEMO_FFMPEGCONTROL_H

#include <pthread.h>
#include <android/native_window.h>
#include "JavaCallback.h"
#include "VideoChannel.h"
#include "AudioChannel.h"
#include "BaseChannel.h"

extern "C" {
#include <libavformat/avformat.h>
#include <libavutil/time.h>
}

//控制层
class FFMPegControl {

public:
//    FFMPegControl(const char *dataSource);
    FFMPegControl(JavaCallback *javaCallback, const char *dataSource);
    ~FFMPegControl();
    void prepare();
    void prepareFFMPeg();
    void start();
    void play();
    void setRenderCallback(RenderFrame renderFrame);

    jint getDuration();

    void seek(jint progress);

    void stop();

    bool isPlaying;
    VideoChannel *videoChannel;
    AudioChannel *audioChannel;
    AVFormatContext *formatContext;

public:
    char *dataSource;
    pthread_t pid_prepare;
    pthread_t pid_play;//直到播放完毕后销毁
    pthread_t pid_stop;//释放线程
    JavaCallback *javaCallback;
    RenderFrame renderFrame;
    int duration;
    bool isSeek;
    pthread_mutex_t seekMutex;
};


#endif //FFMPEGDEMO_FFMPEGCONTROL_H
